let crypto = require('crypto')
const userSecret = ''
const devUserSecret = ''
const getSign = function(originStr) {
  let text = originStr;
  let secret = userSecret // make this your secret!!
  let algorithm = 'sha1'; // consider using sha256
  let hash, hmac;

  // Method 1 - Writing to a stream
  hmac = crypto.createHmac(algorithm, secret);
  hmac.write(text); // write in to the stream
  hmac.end(); // can't read from the stream until you call end()
  hash = hmac.read().toString('base64')
    .replace(/\+/g, '-') // Convert '+' to '-'
    .replace(/\//g, '_') // Convert '/' to '_'
    .replace(/=+$/, ''); // Remove ending '='; // read out hmac digest
  return hash
}
const getDevSign = function(originStr) {
  let text = originStr;
  let secret = devUserSecret // make this your secret!!
  let algorithm = 'sha1'; // consider using sha256
  let hash, hmac;

  // Method 1 - Writing to a stream
  hmac = crypto.createHmac(algorithm, secret);
  hmac.write(text); // write in to the stream
  hmac.end(); // can't read from the stream until you call end()
  hash = hmac.read().toString('base64')
    .replace(/\+/g, '-') // Convert '+' to '-'
    .replace(/\//g, '_') // Convert '/' to '_'
    .replace(/=+$/, ''); // Remove ending '='; // read out hmac digest
  return hash
}

module.exports = {
  getSign,
  getDevSign
}
